var QRCodeInputMethod = IBImgInputMethod.extend({
	size_index: 1,
	menu_node: null,
	size_map: null,
	size_map_text: null,
	size_text: null,
	constructor: function()
	{
		var x = this;
		var menu_handler = function(pos) { x.size_index = pos; x.UpdateText(); return true; }
		var i;

		this.size_map_text = new Array($GFS('Small'),$GFS('Medium'),$GFS('Large'),$GFS('Extra Large'));
		this.size_map = new Array(2,3,4,6);

		this.menu_node = new GFMenuNode($GFS('Select output size'));

		for(i=0;i<this.size_map.length;i++) {
			this.menu_node.SetItem(i,this.size_map_text[i],menu_handler);
		}
	},
	IMName: function()
	{
		return 'QRCode';
	},
	module_name: function()
	{
		return 'QRCodeInputMethod';
	},
	GetLanguage: function()
	{
		return 'util';
	},
	GetMenuNode: function()
	{
		return this.menu_node;
	},
	SuggestionType: function()
	{
		return null;
	},
	isKeyValid: function(key,m)
	{
		if(m != 0 && m != Const.KEY_SHIFT) return false;

		if(32 <= key && key <= 125) return true;
		else return false;
	},
	UpdateText: function()
	{
		this.size_text.SetText(this.size_map_text[this.size_index]);
	},
	onActive: function()
	{
		var factory;
		var x = this;

		factory = this.ime.mainwin.GetExtensionFactory();
		this.size_text = factory.CreateText();
		this.size_text.SetClickHandler(function() { x.size_index = (x.size_index+1)%x.size_map.length; x.UpdateText(); });
		this.UpdateText();

		this.ime.SetPreeditText($GFS('You can press Esc Esc 6 to configure this input method'));
	},
	onDeactive: function()
	{
		this.size_text.Destroy();
		this.size_text = null;
	},
	GetImageUrl: function(buf)
	{
		return 'http://qrcode.kaywa.com/img.php?s='+this.size_map[this.size_index]+'&d=' + encodeURI(buf);
	},
	GetHTMLPostfix: function()
	{
		return '<br />&nbsp;';
	},
	GetTitle: function() 
	{
		return 'QRCode - (' + this.size_map_text[this.size_index] + ')';
	},
	GetInstruction: function()
	{
		return $GFS('Press Enter to complete');
	}
});
